<template>
  <el-form label-width="100px">
    <el-form-item label="备注">
      <el-input v-model="billData.remark"/>
    </el-form-item>
    <el-form-item label="缴费类型">
      <el-select v-model="billData.type" style="width: 100%">
        <el-option value="水费"></el-option>
        <el-option value="电费"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="月份">
      <el-date-picker
          v-model="billData.month"
          placeholder="选择月"
          style="width: 100%"
          type="month"
          value-format="yyyy-MM">
      </el-date-picker>
    </el-form-item>
    <el-form-item label="用量">
      <el-input v-model="billData.amount"/>
    </el-form-item>
    <el-form-item label="单价">
      <el-input v-model="billData.unitPrice"/>
    </el-form-item>
    <el-form-item v-if="!botton" style="text-align: right">
      <el-button type="primary" @click="updateBill()">修改账单</el-button>
    </el-form-item>
    <el-form-item v-if="botton" style="text-align: right">
      <el-button type="primary" @click="addBill()">{{ botton }}</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import {copyObj} from "../../../common/utils";
import {AddBill, UpdateBill} from "../../../network/hydropowerApi";

export default {
  name: "billDialog",
  data() {
    return {
      billData: []
    }
  },
  mounted() {
    if (this.bill) {
      this.billData = copyObj(this.bill)
    }

  },
  methods: {
    //修改账单
    updateBill() {
      UpdateBill(this.billData).then(res => {
        if (res.code === 2000) {
          this.$emit("success");
        }
      })

    },
    //添加账单
    addBill() {
      this.billData.companyUuid = this.uuid
      AddBill(this.billData).then(res => {
        if (res.code === 2000) {
          this.$emit("success");
          this.billData = {}
          this.billData.companyUuid = this.uuid

        }
      })
    },
  },
  props: ['bill', 'botton', 'uuid'],
  watch: {
    'bill': {
      handler() {
        this.billData = copyObj(this.bill)
      }
    },
  }
}
</script>

<style scoped>

</style>